package com.zrfintech.service;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.zrfintech.domain.MgRoleMenuPermission;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class MgRoleMenuPermissionRepo extends MgRoleMenuPermissionRepoI {
    public List<String> getMenuCodeListByRoleCodeList(List<String> roleCodeList) {
        if (CollectionUtils.isEmpty(roleCodeList)) {
            return Lists.newArrayList();
        }
        QueryWrapper<MgRoleMenuPermission> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(ROLE_CODE_COLUMN, roleCodeList);
        List<MgRoleMenuPermission> mgRoleMenuPermissionList = dao.selectList(queryWrapper);
        return CollectionUtil.isEmpty(mgRoleMenuPermissionList)
                ? Lists.newArrayList()
                : mgRoleMenuPermissionList.stream()
                .map(MgRoleMenuPermission::getMenuCode).collect(Collectors.toList());
    }
}
